package com.woniuxy.controller;

import com.woniuxy.entity.Appointment;
import com.woniuxy.service.AppointmentService;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

@Configuration
@EnableScheduling
public class TimerController {
    @Resource
    private AppointmentService appointmentService;

    @Scheduled(cron = "0 0 0 * * ?")//每天凌晨执行
    public void timer() throws Exception{
        List<Appointment> list = appointmentService.selectAppointmentNotOver();
        Date date = new Date();
        for(Appointment appointment:list){
            if(date.after(appointment.getEndTime())){
                appointment.setStatus(4);
                appointmentService.updateAppointment(appointment);
                System.out.println(appointment.getAppointmentId()+"退200押金");
            }
        }
    }
}
